<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

    import {uploadPath} from "@/config/env";
    export default {
        data() {
            return {
                obj: {},
                isIdFind: true,
                initSuccess: false,
                sysUsers: [],
            }
        },
        props: {
            uri: {},
            rowData: {},
        },
        computed: {
            option() {
                return {
                    // size: "small",
                    submitBtn: true,
                    emptyBtn: true,
                    submitText: '提交',
                    emptyText: "关闭",
                    column: [
                        // {
                        //     label: '授权用户',
                        //     prop: 'userId',
                        //     labelWidth: 110,
                        //     maxlength: 64,
                        //     showWordLimit: true,
                        //     span: 20,
                        //     filterable: true,
                        //     type: 'select',
                        //     dicData: this.sysUsers,  // xxxDic 中的的字段映射
                        //     props: {
                        //         label: "fullName",
                        //         value: "id"
                        //     },
                        //     rules: [{
                        //         required: true,
                        //         message: "请输入 用户Id",
                        //         trigger: "blur"
                        //     }]
                        // },
                        // {
                        //     label: '授权ak',
                        //     prop: 'accessKey',
                        //     labelWidth: 110,
                        //     maxlength: 32,
                        //     showWordLimit: true,
                        //     span: 20,
                        //     rules: [{
                        //         required: true,
                        //         message: "请输入 授权ak",
                        //         trigger: "blur"
                        //     }]
                        // },
                        // {
                        //     label: '授权sk',
                        //     prop: 'secretKey',
                        //     labelWidth: 110,
                        //     maxlength: 64,
                        //     showWordLimit: true,
                        //     span: 20,
                        //     rules: [{
                        //         required: true,
                        //         message: "请输入 授权sk",
                        //         trigger: "blur"
                        //     }]
                        // },
                        // {
                        //     label: '有效期',
                        //     prop: 'expireTime',
                        //     type: 'datetime',
                        //     labelWidth: 110,
                        //     format: 'YYYY-MM-DD HH:mm:ss',
                        //     valueFormat: 'YYYY-MM-DD HH:mm:ss',
                        //     span: 20,
                        //     rules: [{
                        //         required: true,
                        //         message: "请选择 有效期",
                        //         trigger: "blur"
                        //     }]
                        // },
                        {
                            label: '备注',
                            prop: 'remarks',
                            labelWidth: 110,
                            maxlength: 256,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 备注",
                                trigger: "blur"
                            }]
                        },

                    ]
                }
            }
        },
        created() {
            this.findSysUsers();
            if (this.isIdFind) {
                this.findId(this.rowData);
            } else {
                this.obj = this.rowData;
                this.initSuccess = true;
            }
        },
        methods: {
            emptytChange() {
                this.$emit('closeDialog', false);
            },
            submit(form, done) {
                this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                    if (res.data.code == 200) {
                        this.$emit('closeDialog', true);
                    }
                    done(form);
                }).catch(err => {
                    console.error(err);
                    done(form);
                })
            },
            findId(rowData) {
                if (rowData != null && rowData.id != null) {
                    this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                         Object.assign(this.obj, res.data.data);
                         this.initSuccess = true;
                    })
                }
             },
            // 查询系统人员
            async findSysUsers() {
                let res = await this.crud.get(this.uri.sysUserList);
                this.sysUsers = res.data.data;
            },
        }
    }
</script>
